package task4_3;

class PetShop {
	private Pet[] pets;
	private int foot;
	
	public Pet[] getPets() {
		return pets;
	}
	public void setPets(Pet[] pets) {
		this.pets = pets;
	}
	public PetShop(int len){
		if(len>0){
			this.pets=new Pet[len];
		}else{
			this.pets=new Pet[1];
		}
	}
	public boolean add(Pet pet){
		if(this.foot<this.pets.length){
			pets[foot]=pet;
			foot++;
			return true;
		}else{
			return false;
		}
	}
	/*public Pet[] addList(Pet[] by){
		Pet list[]=new Pet[10];
		int count=0;
		for(int i=0;i<list.length;i++){
			if(list[i]!=null){
				count++;
			}
		}
		for(int i=0;i<count;i++,count++){
			list[count]=by;
		}
		return list;
	}*/
	public Pet[] search(String keyWord){
		Pet[] p=null;
		int count=0;
		for(int i=0;i<this.pets.length;i++){
			if(this.pets[i]!=null){
				if(this.pets[i].getNo().indexOf(keyWord)!=-1){
					count++;
				}
			}
		}
		p=new Pet[count];
		int f=0;
		for(int i=0;i<this.pets.length;i++){
			if(this.pets[i]!=null){
				if(this.pets[i].getNo().indexOf(keyWord)!=-1){
					p[f]=this.pets[i];
					f++;
				}
			}
		}
		return p;
	}	
}
